﻿using Mengsk.ProxyDelivery.Print.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Mengsk.ProxyDelivery.Print
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private Dictionary<string, Control> controls = new Dictionary<string, Control>();
        private string currentControlName = null;

        public MainWindow()
        {
            InitializeComponent();
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.tbUserName.Text = App.LoginOperator.Name;
            this.tbUserNumber.Text = App.LoginOperator.Number;
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {

        }

        private void LoadControl(string name, Control control, bool useAlreadyExist = true)
        {
            if (name.Equals(currentControlName, StringComparison.Ordinal))
            {
                return;
            }
            this.dpHost.Children.Clear();

            if (controls.ContainsKey(name) && useAlreadyExist)
            {
                this.dpHost.Children.Add(this.controls[name]);
                return;
            }

            this.controls[name] = control;
            this.dpHost.Children.Add(control);
        }

        private void tbDeliveryTemplate_Click(object sender, RoutedEventArgs e)
        {
            this.LoadControl("DeliveryTemplateConfig", new PrintTemplateUserControl());
        }

        private void tbSystemConfig_Click(object sender, RoutedEventArgs e)
        {
            this.LoadControl("SystemConfig", new SystemConfigUserControl());
        }

        private void tbPrint_Click(object sender, RoutedEventArgs e)
        {
            this.LoadControl("Print", new PrintUserControl());
        }

        private void tbPrintHistory_Click(object sender, RoutedEventArgs e)
        {
            this.LoadControl("PrintHistory", new PrintHistoryUserControl());
        }

        private void tbGoodsSum_Click(object sender, RoutedEventArgs e)
        {
            this.LoadControl("GoodsSum", new GoodsCountUserControl());
        }

        private void btnNumberOnline_Click(object sender, RoutedEventArgs e)
        {
            this.LoadControl("WuliuNumber", new WuliuNumberUserControl());
        }
    }
}
